﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ext.Net;
using Sio.Mdm.Entities;
using Sio.Mdm.BF.Ldap;
using Sio.Mdm.Types.Database;
using Sio.Mdm.Client;
using Sio.Mdm.Types;

namespace Sio.Mdm.Web.Instalacija
{
    public partial class LdapLogiSeznam : Controls.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack && !X.IsAjaxRequest)
            {                
                NaloziSeznamGrida(e);                
            }
            
            string iconStatusSuccess = this.ResourceManager1.GetIconUrl(Icon.BulletTick);
            string iconStatusError = this.ResourceManager1.GetIconUrl(Icon.BulletCross);
            string iconStatusWarning = this.ResourceManager1.GetIconUrl(Icon.BulletError);
        }

        #region Private
        private void NaloziSeznamGrida(EventArgs arg)
        {
            GridLogiSeznam.LoadData<LdapLogRazsirjeno>(
                new Filter<LdapLogRazsirjeno>().Where(r => r.LdapLogID != null));
        }       

        #endregion

        #region OdstraniZapise
        protected void OdstraniZapise(object sender, DirectEventArgs e)
        {
            List<int> selectedItems = e.GetIdList<int>("selected", "LdapLogID");
            int deleted = 0;
            foreach (int logId in selectedItems)
            {
                LdapLog log = EntityFactory.LoadEntity<LdapLog>(
                new Filter<LdapLog>().Where(r => r.LdapLogID == logId));
                log.Delete();
                deleted++;
            }
            
            if (deleted > 0)
            {
                StoreLogiSeznam.DataBind();
                ShowExtNotification("Brisanje", String.Format("Brisanje je bilo uspešno. <br><br>Število izbrisanih zapisov: {0}.", deleted));
            }
        }
        #endregion
    }
}
